home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / midas060 / src / mconfig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-16  |  29.2 KB  |  961 lines

  1. /*      MCONFIG.C
  2.  *
  3.  * MIDAS Sound System configuration. Meant to be used with the simplified
  4.  * MIDAS API, MIDAS.C
  5.  *
  6.  * $Id: mconfig.c,v 1.4 1997/01/16 18:41:59 pekangas Exp $
  7.  *
  8.  * Copyright 1996,1997 Housemarque Inc.
  9.  *
  10.  * This file is part of the MIDAS Sound System, and may only be
  11.  * used, modified and distributed under the terms of the MIDAS
  12.  * Sound System license, LICENSE.TXT. By continuing to use,
  13.  * modify or distribute this file you indicate that you have
  14.  * read the license and understand and accept it fully.
  15. */
  16.  
  17. #include "midas.h"
  18. #include "vgatext.h"
  19.  
  20. RCSID(const char *mconfig_rcsid = "$Id: mconfig.c,v 1.4 1997/01/16 18:41:59 pekangas Exp $";)
  21.  
  22.  
  23.  
  24. static char     *title = "MIDAS Sound System v" MVERSTR " configuration";
  25.  
  26. static char     *hexDigits = "0123456789ABCDEF";
  27.  
  28. /* Possible selections for IRQ selection screen: */
  29. #define NUMIRQS 10
  30. static int      IRQs[NUMIRQS] = { 2, 3, 4, 5, 7, 9, 10, 11, 12, 15 };
  31. static char     *IRQStrings[NUMIRQS] = {
  32.     "2", "3", "4", "5", "7", "9", "10", "11", "12", "15" };
  33.  
  34. /* Possible selections for DMA channel selection screen: */
  35. #define NUMDMAS 6
  36. static int      DMAs[NUMDMAS] = { 0, 1, 3, 5, 6, 7 };
  37. static char     *DMAStrings[NUMDMAS] = { "0", "1", "3", "5", "6", "7" };
  38.  
  39. /* Possible selections for mixing rate selection screen: */
  40. #define NUMRATES 7
  41. #define DEFAULTRATE 6
  42. static unsigned mixRates[NUMRATES] = {
  43.     8000, 11025, 16000, 22050, 32000, 38000, 44100 };
  44. static char     *mixRateStrings[NUMRATES+1] = {
  45.     "8000Hz", "11025Hz", "16000Hz", "22050Hz", "32000Hz", "38000Hz",
  46.     "44100Hz", "Other" };
  47.  
  48. /* Possible selections for output mode selection screen: */
  49. #define DEFAULTBITS sd16bit
  50. #define DEFAULTSTEREO sdStereo
  51. #define NUMMODES 4
  52. static unsigned outputModes[NUMMODES] = {
  53.     sd8bit | sdMono,
  54.     sd8bit | sdStereo,
  55.     sd16bit | sdMono,
  56.     sd16bit | sdStereo };
  57. static char     *outputModeStrings[NUMMODES] = {
  58.     "8-bit mono",
  59.     "8-bit stereo",
  60.     "16-bit mono",
  61.     "16-bit stereo" };
  62.  
  63. static int      detectedSD;             /* detected Sound Device number */
  64.  
  65.  
  66.  
  67.  
  68. /****************************************************************************\
  69. *
  70. * Function:     void InitScreen(void);
  71. *
  72. * Description:  Initializes the display mode and draws the screen.
  73. *
  74. \****************************************************************************/
  75.  
  76. static void InitScreen(void)
  77. {
  78.     int         y;
  79.     int         x;
  80.  
  81.     /* Set up standard 80x25 text mode: */
  82.     vgaSetMode(3);
  83.     vgaSetWidth(80);
  84.  
  85.     /* Hide cursor by moving it outside the display area: */
  86.     vgaMoveCursor(0, 26);
  87.  
  88.     /* Fill whole screen with blue: */
  89.     vgaFillRect(1, 1, 80, 25, 0x10);
  90.  
  91.     /* Write display texts: */
  92.     x = 40 - mStrLength(title)/2;
  93.     vgaWriteStr(x, 1, title, 0x13, mStrLength(title));
  94.     vgaDrawChars(x, 2, 0xC4, 0x13, mStrLength(title));
  95. /*    vgaWriteText(x, 2, "\xFF\x13\x7F\x27─"); */
  96.     vgaWriteStr(13, 24, "Use arrows to select, Enter to confirm or Esc to "
  97.         "cancel", 0x13, 55);
  98.  
  99.     /* Draw the menu box in the middle of the screen: */
  100.     vgaWriteText(7, 4, "\xFF\x1F\x7F\x43▄\xFF\x18▄");
  101.     vgaWriteText(7, 5, "\xFF\x7F█\x7F\x42 \xFF\x78█");
  102.     vgaWriteText(7, 6, "\xFF\x7F█ \xFF\x78┌\x7F\x3E─\xFF\x7F┐ \xFF\x78█");
  103.     for ( y = 7; y < 21; y++ )
  104.         vgaWriteText(7, y, "\xFF\x7F█ \xFF\x78│\x7F\x3E \xFF\x7F│ \xFF\x78█");
  105.     vgaWriteText(7, 21, "\xFF\x7F█ \xFF\x78└\xFF\x7F\x7F\x3E─┘ \xFF\x78█");
  106.     vgaWriteText(7, 22, "\xFF\x1F▀\xFF\x18\x7F\x43▀");
  107. }
  108.  
  109.  
  110.  
  111. /****************************************************************************\
  112. *
  113. * Function:     int AskSelection(char *selTitle, char **selections,
  114. *                   int numSelections, int defaultSel)
  115. *
  116. * Description:  Get a menu selection from the user
  117. *
  118. * Input:        char *selTitle          selection title (ie. "Select sound
  119. *                                       card")
  120. *               char **selections       pointer to array of pointers to
  121. *                                       possible selections (ASCIIZ)
  122. *               int numSelections       number of possible selections
  123. *               int defaultSel          default selection
  124. *
  125. * Returns:      User selection (0 - (numSelections-1)) or -1 if Esc was
  126. *               pressed.
  127. *
  128. \****************************************************************************/
  129.  
  130. static int AskSelection(char *selTitle, char **selections, int numSelections,
  131.     int defaultSel)
  132. {
  133.     int         current, first;
  134.     int         selDone, n, a, y;
  135.  
  136.     current = defaultSel;
  137.     first = 0;
  138.     selDone = 0;
  139.  
  140.     /* write title string: */
  141.     vgaWriteStr(8, 5, "", 0x70, 66);
  142.     vgaWriteStr(40 - mStrLength(selTitle)/2, 5, selTitle, 0x70,
  143.         mStrLength(selTitle));
  144.  
  145.     /* loop until Enter or Esc has been pressed: */
  146.     while ( !selDone )
  147.     {
  148.         /* draw all menu entries, with the current one highlighted: */
  149.         for ( n = 0; n < 14; n++ )
  150.         {
  151.             y = 7 + n;
  152.             if ( n < (numSelections-first) )
  153.             {
  154.                 /* if the entry that is being drawn is selected, highlight
  155.                    it: */
  156.                 if ( (n + first) != current )
  157.                     a = 0x70;
  158.                 else
  159.                     a = 0x07;
  160.  
  161.                 /* draw a space at the leftmost column: */
  162.                 vgaDrawChar(10, y, ' ', a);
  163.                 /* draw the menu entry: */
  164.                 vgaWriteStr(11, y, selections[n+first], a, 61);
  165.             }
  166.             else
  167.                 vgaWriteStr(10, y, "", 0x70, 62);
  168.         }
  169.  
  170.         /* wait for a keypress and process it: */
  171.         switch ( mGetKey() )
  172.         {
  173.             case 27:                    /* Escape */
  174.                 return -1;              /* return -1 - cancel */
  175.  
  176.             case 13:                    /* Enter */
  177.                 return current;         /* return current selection */
  178.  
  179.             case 0x148:                 /* Up arrow */
  180.                 if ( current > 0 )
  181.                     current--;          /* select previous one */
  182.                 if ( current < first )  /* scroll up if necessary */
  183.                     first = current;
  184.                 break;
  185.  
  186.             case 0x150:                 /* down arrow */
  187.                 if ( current < (numSelections-1) )
  188.                     current++;          /* select next one */
  189.                 if ( current > (first + 13) )   /* scroll down if */
  190.                     first = current - 13;       /* necessary */
  191.                 break;
  192.         }
  193.     }
  194.  
  195.     return -1;
  196. }
  197.  
  198.  
  199.  
  200.  
  201. /****************************************************************************\
  202. *
  203. * Function:     void PromptString(char *title, int maxLength, char *str);
  204. *
  205. * Description:  Prompts the user for a string in a separate window.
  206. *
  207. * Input:        char *title             window title (determines window
  208. *                                       width)
  209. *               int maxLength           maximum string length
  210. *               char *str               pointer to a buffer where the string
  211. *                                       will be stored.
  212. *
  213. * Returns:      1 if a string was entered (Enter was pressed), 0 if not
  214. *               (Escape pressed).
  215. *
  216. \****************************************************************************/
  217.  
  218. static int PromptString(char *title, int maxLength, char *str)
  219. {
  220.     int         x;
  221.     int         width;
  222.     int         strPos, done;
  223.     int         strOK;
  224.     int         key;
  225.  
  226.     /* calculate window width: */
  227.     width = mStrLength(title) + 2;
  228.  
  229.     x = 40 - (width+1)/2;
  230.  
  231.     /* draw window: */
  232.     vgaDrawChar(x, 10, '█', 0x3B);
  233.     vgaDrawChars(x+1, 10, '▀', 0x3B, width);
  234.     vgaDrawChar(x+width+1, 10, '█', 0x38);
  235.  
  236.     vgaWriteText(x, 11, "\xFF\x3B█ ");
  237.     vgaWriteText(x+width, 11, "\xFF\x38 █");
  238.     vgaWriteStr(x+2, 11, title, 0x30, width-2);
  239.  
  240.     vgaWriteText(x, 12, "\xFF\x3B█ \xFF\x38┌");
  241.     vgaDrawChars(x+3, 12, '─', 0x38, width-4);
  242.     vgaWriteText(x+width-1, 12, "\xFF\x3B┐ \xFF\x38█");
  243.  
  244.     vgaWriteText(x, 13, "\xFF\x3B█ \xFF\x38│");
  245.     vgaDrawChars(x+3, 13, ' ', 0x30, width-4);
  246.     vgaWriteText(x+width-1, 13, "\xFF\x3B│ \xFF\x38█");
  247.  
  248.     vgaWriteText(x, 14, "\xFF\x3B█ \xFF\x38└");
  249.     vgaDrawChars(x+3, 14, '─', 0x3B, width-4);
  250.     vgaWriteText(x+width-1, 14, "\xFF\x3B┘ \xFF\x38█");
  251.  
  252.     vgaDrawChar(x, 15, '█', 0x3B);
  253.     vgaDrawChars(x+1, 15, '▄', 0x38, width);
  254.     vgaDrawChar(x+width+1, 15, '█', 0x38);
  255.  
  256.     strPos = 0;
  257.     done = 0;
  258.     strOK = 0;
  259.     str[0] = 0;
  260.     while ( !done )
  261.     {
  262.         /* write current string to screen: */
  263.         vgaWriteStr(x+3, 13, &str[0], 0x30, maxLength);
  264.  
  265.         /* move cursor to end of string: */
  266.         vgaMoveCursor(x + 3 + mStrLength(&str[0]), 13);
  267.  
  268.         key = mGetKey();                /* get keypress */
  269.         switch ( key )
  270.         {
  271.             case 27:                    /* Escape */
  272.                 strOK = 0;
  273.                 done = 1;
  274.                 break;
  275.  
  276.             case 13:                    /* Enter */
  277.                 strOK = 1;
  278.                 done = 1;
  279.                 break;
  280.  
  281.             case 8:                     /* BackSpace */
  282.                 if ( strPos > 0 )
  283.                 {
  284.                     strPos--;
  285.                     str[strPos] = 0;
  286.                 }
  287.                 break;
  288.  
  289.             default:
  290.                 /* Some other key was pressed. If the key is not a control
  291.                    character or an extended keycode, append it to the end of
  292.                    the string provided that it's not already too long: */
  293.                 if ( (key >= ' ') && (key <= 255) && (strPos < maxLength) )
  294.                 {
  295.                     str[strPos] = key;
  296.                     strPos++;
  297.                     str[strPos] = 0;
  298.                 }
  299.                 break;
  300.         }
  301.     }
  302.  
  303.     /* Hide cursor by moving it out of the screen: */
  304.     vgaMoveCursor(1, 26);
  305.  
  306.     if ( strOK == 1 )
  307.         return 1;
  308.     return 0;
  309. }
  310.  
  311.  
  312.  
  313.  
  314. /****************************************************************************\
  315. *
  316. * Function:     int SelectCard(int *selected)
  317. *
  318. * Description:  Gets a sound card selection from the user. Updates
  319. *               midasSDNumber and midasSDCard.
  320. *
  321. * Returns:      MIDAS error code. *selected contains 1 if selection was
  322. *               successful (Enter was pressed) or 0 if not (Escape).
  323. *
  324. \****************************************************************************/
  325.  
  326. static int SelectCard(int *selected)
  327. {
  328.     char        **cardNames;            /* sound card names */
  329.     int         *cardSDs;               /* Sound Device number corresponding
  330.                                            to each sound card selection */
  331.     int         *cardTypes;             /* SD sound card type corresponding
  332.                                            to each sound card selection */
  333.     int         numCards;               /* total number of card selections */
  334.     int         sdNum, cardNum, i;
  335.     int         error;
  336.     SoundDevice *SD;
  337.  
  338.     /* find the total number of sound cards: */
  339.     numCards = 0;
  340.     for ( sdNum = 0; sdNum < NUMSDEVICES; sdNum++ )
  341.         numCards += midasSoundDevices[sdNum]->numCardTypes;
  342.  
  343.     /* allocate memory for card name pointers: */
  344.     if ( (error = memAlloc(numCards * sizeof(char*), (void**) &cardNames))
  345.         != OK )
  346.         midasError(error);
  347.  
  348.     /* allocate memory for Sound Device numbers: */
  349.     if ( (error = memAlloc(numCards * sizeof(int), (void**) &cardSDs)) != OK )
  350.         midasError(error);
  351.  
  352.     /* allocate memory for sound card type numbers: */
  353.     if ( (error = memAlloc(numCards * sizeof(int), (void**) &cardTypes))
  354.         != OK )
  355.         midasError(error);
  356.  
  357.     /* Set all entries in cardNames[], cardSDs[] and cardTypes[] to their
  358.        correct values: */
  359.     cardNum = 0;
  360.     for ( sdNum = 0; sdNum < NUMSDEVICES; sdNum++ )
  361.     {
  362.         /* Point SD to current Sound Device: */
  363.         SD = midasSoundDevices[sdNum];
  364.  
  365.         /* Do for all sound card possibilities for this SD: */
  366.         for ( i = 0; i < SD->numCardTypes; i++ )
  367.         {
  368.             cardSDs[cardNum] = sdNum;
  369.             cardNames[cardNum] = SD->cardNames[i];
  370.             cardTypes[cardNum] = i + 1;
  371.             cardNum++;
  372.         }
  373.     }
  374.  
  375.     /* Attempt to autodetect sound card type: */
  376.     midasDetectSD();
  377.     detectedSD = midasSDNumber;
  378.  
  379.     /* If a Sound Device was detected, attempt to find a sound card from
  380.        the selections which corresponds to the detected type: */
  381.     cardNum = 0;
  382.     if ( midasSDNumber != -1 )
  383.     {
  384.         for ( i = 0; i < numCards; i++ )
  385.         {
  386.             /* If the Sound Device number and card type number match, this
  387.                is the correct sound card */
  388.             if ( (cardSDs[i] == midasSDNumber) &&
  389.                  (cardTypes[i] == midasSD->cardType) )
  390.                 cardNum = i;
  391.         }
  392.     }
  393.  
  394.     /* Get user sound card selection: */
  395.     cardNum = AskSelection("Select Sound Card", cardNames, numCards, cardNum);
  396.  
  397.     /* If a card was selected, set up midasSDNumber, midasSDCard and
  398.        midasSD variables for later use: */
  399.     if ( cardNum != -1 )
  400.     {
  401.         midasSDNumber = cardSDs[cardNum];
  402.         midasSDCard = cardTypes[cardNum];
  403.         midasSD = midasSoundDevices[midasSDNumber];
  404.  
  405.         *selected = 1;                  /* selected succesfully */
  406.     }
  407.     else
  408.     {
  409.         /* Esc was pressed - no sound card selected */
  410.         *selected = 0;
  411.     }
  412.  
  413.     /* Deallocate sound card names: */
  414.     if ( (error = memFree(cardNames)) != OK )
  415.         midasError(error);
  416.  
  417.     /* Deallocate sound card Sound Device numbers: */
  418.     if ( (error = memFree(cardSDs)) != OK )
  419.         midasError(error);
  420.  
  421.     /* Deallocate sound card type numbers: */
  422.     if ( (error = memFree(cardTypes)) != OK )
  423.         midasError(error);
  424.  
  425.     return OK;
  426. }
  427.  
  428.  
  429.  
  430.  
  431. /****************************************************************************\
  432. *
  433. * Function:     int SelectPort(int *selected)
  434. *
  435. * Description:  Gets a sound card I/O port selection from the user. Updates
  436. *               midasSDPort. Assumes that midasSD points to the correct
  437. *               Sound Device.
  438. *
  439. * Returns:      MIDAS error code. *selected contains 1 if selection was
  440. *               successful (Enter was pressed) or 0 if not (Escape).
  441. *
  442. \****************************************************************************/
  443.  
  444. static int SelectPort(int *selected)
  445. {
  446.     int         numPorts;               /* number of port values */
  447.     char        **portStrs;             /* pointers to port value strings */
  448.     unsigned    *portValues;            /* port values */
  449.     int         error;
  450.     int         portNum, i;
  451.     int         portValue;
  452.     int         defaultSel;
  453.     static int  result;
  454.     long        portVal;
  455.     static char promptStr[4];
  456.  
  457.     numPorts = midasSD->numPortAddresses;
  458.  
  459.     /* If the selected Sound Device is not the one initially detected,
  460.        call its Detect() routine to autodetect port, IRQ and DMA values:
  461.        (Borland Pascal extender seems to cause some problems if the PAS
  462.        detection routine is called twice) */
  463.     if ( midasSDNumber != detectedSD )
  464.         if ( (error = midasSD->Detect(&result)) != OK )
  465.             midasError(error);
  466.  
  467.     /* Allocate memory for I/O port string pointers: */
  468.     if ( (error = memAlloc((numPorts+1) * sizeof(char*), (void**) &portStrs))
  469.         != OK )
  470.         midasError(error);
  471.  
  472.     /* Point portValues to Sound Device port address table: */
  473.     portValues = midasSD->portAddresses;
  474.  
  475.     defaultSel = 0;
  476.     for ( portNum = 0; portNum < numPorts; portNum++ )
  477.     {
  478.         /* Allocate memory for port number string ("xxxh\0"): */
  479.         if ( (error = memAlloc(5, (void**) &portStrs[portNum])) != OK )
  480.             midasError(error);
  481.  
  482.         portValue = portValues[portNum];
  483.  
  484.         /* Convert port value to a hexadecimal number: */
  485.         portStrs[portNum][0] = hexDigits[portValue >> 8];
  486.         portStrs[portNum][1] = hexDigits[(portValue >> 4) & 0x0F];
  487.         portStrs[portNum][2] = hexDigits[portValue & 0x0F];
  488.         portStrs[portNum][3] = 'h';
  489.         portStrs[portNum][4] = 0;
  490.  
  491.         /* If current port value is equal to the SD port field, set this
  492.            one as the default: */
  493.         if ( portValue == midasSD->port)
  494.             defaultSel = portNum;
  495.     }
  496.  
  497.     /* Add "Other" as the last selection: */
  498.     portStrs[numPorts] = "Other";
  499.  
  500.     /* Ask the user for the port number: */
  501.     portNum = AskSelection("Select Sound Card I/O Port Address", portStrs,
  502.         numPorts+1, defaultSel);
  503.  
  504.     if ( portNum != -1 )
  505.     {
  506.         /* Enter was pressed - if the selection was not "Other", place the
  507.            selected port address to midasSDPort: */
  508.         if ( portNum != numPorts )
  509.         {
  510.             midasSDPort = portValues[portNum];
  511.         }
  512.         else
  513.         {
  514.             /* "Other" was selected - prompt the user for the port value */
  515.             portVal = -1;
  516.             while ( portVal == -1 )
  517.             {
  518.                 /* prompt the user for port value */
  519.                 if ( PromptString("Enter Sound Card I/O Port Address "
  520.                     "(in HEXADECIMAL)", 3, &promptStr[0]) == 0 )
  521.                 {
  522.                     /* PromptString() returned 0 - Escape was pressed */
  523.                     selected = 0;
  524.                     return OK;
  525.                 }
  526.  
  527.                 /* Convert string to a long integer. If an illegal string
  528.                    had been entered, the value will be -1 and the user will
  529.                    be prompted for it again. */
  530.                 portVal = mHex2Long(&promptStr[0]);
  531.             }
  532.  
  533.             /* Set the entered port value to midasSDPort: */
  534.             midasSDPort = portVal;
  535.         }
  536.         *selected = 1;
  537.     }
  538.     else
  539.         *selected = 0;
  540.  
  541.     /* Deallocate the memory allocated for each port number string: */
  542.     for ( i = 0; i < numPorts; i++ )
  543.     {
  544.         if ( (error = memFree(portStrs[i])) != OK )
  545.             midasError(error);
  546.     }
  547.  
  548.     /* Deallocate port number string pointers: */
  549.     if ( (error = memFree(portStrs)) != OK )
  550.         midasError(error);
  551.  
  552.     return OK;
  553. }
  554.  
  555.  
  556.  
  557.  
  558. /****************************************************************************\
  559. *
  560. * Function:     int SelectIRQ(int *selected)
  561. *
  562. * Description:  Gets a sound card IRQ number selection from the user. Updates
  563. *               midasSDIRQ. Assumes that midasSD points to the correct
  564. *               Sound Device.
  565. *
  566. * Returns:      MIDAS error code. *selected contains 1 if selection was
  567. *               successful (Enter was pressed) or 0 if not (Escape).
  568. *
  569. \****************************************************************************/
  570.  
  571. static int SelectIRQ(int *selected)
  572. {
  573.     int         IRQNum;
  574.     int         i;
  575.  
  576.     /* Search through IRQ value table to find the entry that corresponds to
  577.        the current Sound Device IRQ number: */
  578.     IRQNum = 0;
  579.     for ( i = 0; i < NUMIRQS; i++ )
  580.     {
  581.         if ( IRQs[i] == midasSD->IRQ )
  582.             IRQNum = i;
  583.     }
  584.  
  585.     /* Get the user IRQ selection: */
  586.     IRQNum = AskSelection("Select Sound Card IRQ Number",
  587.         (char**) &IRQStrings[0], NUMIRQS, IRQNum);
  588.  
  589.     if ( IRQNum != -1 )
  590.     {
  591.         /* Enter was pressed - set selected IRQ number to midasSDIRQ: */
  592.         midasSDIRQ = IRQs[IRQNum];
  593.         *selected = 1;
  594.     }
  595.     else
  596.     {
  597.         /* Escape was pressed - do not set IRQ number */
  598.         *selected = 0;
  599.     }
  600.  
  601.     return OK;
  602. }
  603.  
  604.  
  605.  
  606.  
  607. /****************************************************************************\
  608. *
  609. * Function:     int SelectDMA(int *selected)
  610. *
  611. * Description:  Gets a sound card DMA channel number selection from the user.
  612. *               Updates midasSDDMA. Assumes that midasSD points to the correct
  613. *               Sound Device.
  614. *
  615. * Returns:      MIDAS error code. *selected contains 1 if selection was
  616. *               successful (Enter was pressed) or 0 if not (Escape).
  617. *
  618. \****************************************************************************/
  619.  
  620. static int SelectDMA(int *selected)
  621. {
  622.     int         DMANum;
  623.     int         i;
  624.  
  625.     /* Search through DMA value table to find the entry that corresponds to
  626.        the current Sound Device DMA number: */
  627.     DMANum = 0;
  628.     for ( i = 0; i < NUMDMAS; i++ )
  629.     {
  630.         if ( DMAs[i] == midasSD->DMA )
  631.             DMANum = i;
  632.     }
  633.  
  634.     /* Get the user IRQ selection: */
  635.     DMANum = AskSelection("Select Sound Card DMA Channel Number",
  636.         (char**) &DMAStrings[0], NUMDMAS, DMANum);
  637.  
  638.     if ( DMANum != -1 )
  639.     {
  640.         /* Enter was pressed - set selected DMA number to midasSDDMA: */
  641.         midasSDDMA = DMAs[DMANum];
  642.         *selected = 1;
  643.     }
  644.     else
  645.     {
  646.         /* Escape was pressed - do not set IRQ number */
  647.         *selected = 0;
  648.     }
  649.  
  650.     return OK;
  651. }
  652.  
  653.  
  654.  
  655.  
  656. /****************************************************************************\
  657. *
  658. * Function:     int SelectMixRate(int *selected)
  659. *
  660. * Description:  Gets a mixing rate selection from the user. Updates
  661. *               midasMixRate. Assumes that midasSD points to the correct
  662. *               Sound Device.
  663. *
  664. * Returns:      MIDAS error code. *selected contains 1 if selection was
  665. *               successful (Enter was pressed) or 0 if not (Escape).
  666. *
  667. \****************************************************************************/
  668.  
  669. static int SelectMixRate(int *selected)
  670. {
  671.     int         rateNum;
  672.     long        rateVal;
  673.     static char promptStr[6];
  674.  
  675.     /* Get mixing rate selection from user: */
  676.     rateNum = AskSelection("Select mixing rate", (char**) &mixRateStrings[0],
  677.         NUMRATES+1, DEFAULTRATE);
  678.  
  679.     if ( rateNum != -1 )
  680.     {
  681.         /* A selection was made. If the selected value was not "Other",
  682.            update midasMixRate: */
  683.         if ( rateNum != NUMRATES )
  684.         {
  685.             midasMixRate = mixRates[rateNum];
  686.         }
  687.         else
  688.         {
  689.             /* "Other" was selected - prompt the user for mixing rate */
  690.             rateVal = -1;
  691.             while ( rateVal == -1 )
  692.             {
  693.                 /* prompt the user for mixing rate: */
  694.                 if ( PromptString("Enter Mixing Rate (in DECIMAL)", 5,
  695.                     &promptStr[0]) == 0 )
  696.                 {
  697.                     /* PromptString() returned 0 - Escape was pressed */
  698.                     selected = 0;
  699.                     return OK;
  700.                 }
  701.  
  702.                 /* Convert string to a long integer. If an illegal string
  703.                    had been entered, the value will be -1 and the user will
  704.                    be prompted for it again. */
  705.                 rateVal = mDec2Long(&promptStr[0]);
  706.  
  707.                 /* Do not allow values larger than 65535 to prevent
  708.                    overflows: */
  709.                 if ( rateVal > 65535 )
  710.                     rateVal = -1;
  711.             }
  712.  
  713.             /* Set the entered value to midasMixRate: */
  714.             midasMixRate = rateVal;
  715.         }
  716.  
  717.         *selected = 1;
  718.     }
  719.     else
  720.         *selected = 0;
  721.  
  722.     return OK;
  723. }
  724.  
  725.  
  726.  
  727. /****************************************************************************\
  728. *
  729. * Function:     int SelectOutputMode(int *selected)
  730. *
  731. * Description:  Gets a output mode selection from the user. Updates
  732. *               midasOutputMode. Assumes that midasSD points to the correct
  733. *               Sound Device.
  734. *
  735. * Returns:      MIDAS error code. *selected contains 1 if selection was
  736. *               successful (Enter was pressed) or 0 if not (Escape).
  737. *
  738. \****************************************************************************/
  739.  
  740. static int SelectOutputMode(int *selected)
  741. {
  742.     int         modeNum;
  743.     int         numModes = 0;
  744.     static char *modeStr[NUMMODES];
  745.     unsigned    modeBits[NUMMODES];
  746.     int         defaultMode = 0;
  747.     unsigned    sdModes = midasSD->modes;   /* available Sound Device modes */
  748.  
  749.  
  750.     /* Search through outputModes[] table to find the output modes the
  751.        Sound Device is capable of playing and add them to modeStr[]
  752.        and modeBits[]: */
  753.     for ( modeNum = 0; modeNum < NUMMODES; modeNum++ )
  754.     {
  755.         if ( (sdModes & outputModes[modeNum]) == outputModes[modeNum] )
  756.         {
  757.             /* Sound Device can play mode modeNum - add to tables: */
  758.             modeStr[numModes] = outputModeStrings[modeNum];
  759.             modeBits[numModes] = outputModes[modeNum];
  760.  
  761.             /* If the current mode is DEFAULTSTEREO (sdMono usually), set it
  762.                as the default output mode - 16-bit modes always follow 8-bit
  763.                modes in the list: */
  764.             if ( (outputModes[modeNum] & DEFAULTSTEREO) == DEFAULTSTEREO )
  765.                 defaultMode = numModes;
  766.  
  767.             numModes++;
  768.         }
  769.     }
  770.  
  771.  
  772.     /* Get output mode selection from user: */
  773.     if (numModes>1) {
  774.       modeNum = AskSelection("Select output mode", modeStr, numModes, defaultMode);
  775.     } else modeNum=defaultMode;
  776.  
  777.     if ( modeNum != -1 )
  778.     {
  779.         /* A selection was made - update midasOutputMode: */
  780.         midasOutputMode = modeBits[modeNum];
  781.         *selected = 1;
  782.     }
  783.     else
  784.         *selected = 0;
  785.  
  786.     return OK;
  787. }
  788.  
  789.  
  790.  
  791. /****************************************************************************\
  792. *
  793. * Function:     int midasConfig(void)
  794. *
  795. * Description:  MIDAS Sound System configuration. Prompts the user for all
  796. *               configuration information and sets the MIDAS variables
  797. *               accordingly. Call before midasInit() but after
  798. *               midasSetDefaults().
  799. *
  800. * Returns:      1 if configuration was successful, 0 if not (Esc was pressed)
  801. *
  802. \****************************************************************************/
  803.  
  804. int CALLING midasConfig(void)
  805. {
  806.     static int  selected;
  807.  
  808.     InitScreen();
  809.     SelectCard(&selected);
  810.     if ( selected && (midasSD->configBits & sdUsePort) )
  811.         SelectPort(&selected);
  812.     if ( selected && (midasSD->configBits & sdUseIRQ) )
  813.         SelectIRQ(&selected);
  814.     if ( selected && (midasSD->configBits & sdUseDMA) )
  815.         SelectDMA(&selected);
  816.     if ( selected && (midasSD->configBits & sdUseMixRate) )
  817.         SelectMixRate(&selected);
  818.     if ( selected && (midasSD->configBits & sdUseOutputMode) )
  819.         SelectOutputMode(&selected);
  820.  
  821.     /* Move cursor to top left corner of the screen: */
  822.     vgaMoveCursor(0, 0);
  823.  
  824.     /* Fill whole screen with black background, white foreground: */
  825.     vgaFillRect(1, 1, 80, 25, 0x07);
  826.  
  827.     return selected;
  828. }
  829.  
  830.  
  831. #ifndef NOLOADERS
  832.  
  833.  
  834.  
  835. /****************************************************************************\
  836. *
  837. * Function:     int midasLoadConfig(char *fileName);
  838. *
  839. * Description:  Loads configuration from file saved using midasSaveConfig().
  840. *
  841. * Input:        char *fileName          configuration file name, ASCIIZ
  842. *
  843. * Returns:      1 if successful, 0 if file not found.
  844. *
  845. \****************************************************************************/
  846.  
  847. void CALLING midasLoadConfig(char *fileName)
  848. {
  849.     static fileHandle  f;
  850.     int         error;
  851.  
  852.     /* open configuration file: */
  853.     if ( (error = fileOpen(fileName, fileOpenRead, &f)) != OK )
  854.         midasError(error);
  855.  
  856.     /* read Sound Device number: */
  857.     if ( (error = fileRead(f, &midasSDNumber, sizeof(int))) != OK )
  858.         midasError(error);
  859.  
  860.     /* read sound card type: */
  861.     if ( (error = fileRead(f, &midasSDCard, sizeof(int))) != OK )
  862.         midasError(error);
  863.  
  864.     /* read Sound Device I/O port number: */
  865.     if ( (error = fileRead(f, &midasSDPort, sizeof(int))) != OK )
  866.         midasError(error);
  867.  
  868.     /* read Sound Device IRQ number: */
  869.     if ( (error = fileRead(f, &midasSDIRQ, sizeof(int))) != OK )
  870.         midasError(error);
  871.  
  872.     /* read Sound Device DMA channel number: */
  873.     if ( (error = fileRead(f, &midasSDDMA, sizeof(int))) != OK )
  874.         midasError(error);
  875.  
  876.     /* read mixing rate: */
  877.     if ( (error = fileRead(f, &midasMixRate, sizeof(unsigned))) != OK )
  878.         midasError(error);
  879.  
  880.     /* read output mode: */
  881.     if ( (error = fileRead(f, &midasOutputMode, sizeof(unsigned))) != OK )
  882.         midasError(error);
  883.  
  884.     /* close configuration file: */
  885.     if ( (error = fileClose(f)) != OK )
  886.         midasError(error);
  887. }
  888.  
  889.  
  890.  
  891.  
  892. /****************************************************************************\
  893. *
  894. * Function:     void midasSaveConfig(char *fileName);
  895. *
  896. * Description:  Saves configuration to a file
  897. *
  898. * Input:        char *fileName          configuration file name, ASCIIZ
  899. *
  900. \****************************************************************************/
  901.  
  902. void CALLING midasSaveConfig(char *fileName)
  903. {
  904.     static fileHandle  f;
  905.     int         error;
  906.  
  907.     /* open configuration file: */
  908.     if ( (error = fileOpen(fileName, fileOpenWrite, &f)) != OK )
  909.         midasError(error);
  910.  
  911.     /* write Sound Device number: */
  912.     if ( (error = fileWrite(f, &midasSDNumber, sizeof(int))) != OK )
  913.         midasError(error);
  914.  
  915.     /* write sound card type: */
  916.     if ( (error = fileWrite(f, &midasSDCard, sizeof(int))) != OK )
  917.         midasError(error);
  918.  
  919.     /* write Sound Device I/O port number: */
  920.     if ( (error = fileWrite(f, &midasSDPort, sizeof(int))) != OK )
  921.         midasError(error);
  922.  
  923.     /* write Sound Device IRQ number: */
  924.     if ( (error = fileWrite(f, &midasSDIRQ, sizeof(int))) != OK )
  925.         midasError(error);
  926.  
  927.     /* write Sound Device DMA channel number: */
  928.     if ( (error = fileWrite(f, &midasSDDMA, sizeof(int))) != OK )
  929.         midasError(error);
  930.  
  931.     /* write mixing rate: */
  932.     if ( (error = fileWrite(f, &midasMixRate, sizeof(unsigned))) != OK )
  933.         midasError(error);
  934.  
  935.     /* write output mode: */
  936.     if ( (error = fileWrite(f, &midasOutputMode, sizeof(unsigned))) != OK )
  937.         midasError(error);
  938.  
  939.     /* close configuration file: */
  940.     if ( (error = fileClose(f)) != OK )
  941.         midasError(error);
  942. }
  943.  
  944. #endif
  945.  
  946.  
  947. /*
  948.  * $Log: mconfig.c,v $
  949.  * Revision 1.4  1997/01/16 18:41:59  pekangas
  950.  * Changed copyright messages to Housemarque
  951.  *
  952.  * Revision 1.3  1996/08/06 18:45:47  pekangas
  953.  * Fixed title text width and underlining
  954.  *
  955.  * Revision 1.2  1996/06/06 20:32:14  pekangas
  956.  * Changed to clear the screen after setup
  957.  *
  958.  * Revision 1.1  1996/05/22 20:49:33  pekangas
  959.  * Initial revision
  960.  *
  961. */